/*
 * @Company: TWL
 * @Author: xue jian
 * @Email: xuejian@kanzhun.com
 * @Date: 2019-12-30 16:51:26
 */
#include "util.h"
#include <string>
#include <iostream>
#include "rocksdb/db.h"
#include <fstream>
int main() {
    rocksdb::DB* db;
    rocksdb::Options options;
    options.create_if_missing = true;

    std::ifstream infile("haha/metafile");
    json j_meta;
    infile>>j_meta;
    infile.close();
    // std::cout<<j_meta;
    for (auto& file:j_meta["files"]) {
        file["db_path"] = "haha";
    }
    infile.close();
    rocksdb::ExportImportFilesMetaData metadata(get_sstmeta_from_json(j_meta));
    


    rocksdb::Status status = rocksdb::DB::Open(options, "new_rocks", &db);
    rocksdb::ColumnFamilyHandle* test2;
    rocksdb::ImportColumnFamilyOptions i_options;
    i_options.move_files = true;
    db->CreateColumnFamilyWithImport(rocksdb::ColumnFamilyOptions(), "haha", i_options, metadata, &test2);
    system("rm -rf haha");
    std::string value2;
    std::string key("5");
    status = db->Get(rocksdb::ReadOptions(), test2, key, &value2);
    if (status.ok()) {
        std::cout<<"get the value ok"<<std::endl;
    }
    std::cout<<value2<<std::endl;

    delete db;
}